#include "FiveWin.ch"

#define BM_SETCHECK (WM_USER+1)

//----------------------------------------------------------------------------//

CLASS TCheckBox FROM TControl

   DATA   bSetGet, bClick

   METHOD New( nRow, nCol, cCaption, bSetGet, oWnd, nWidth, nHeight,;
               nHelpTopic, bClick, oFont ) CONSTRUCTOR
   METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, bClick ) CONSTRUCTOR
   METHOD Click()
   METHOD cToChar() BLOCK { | Self | Super:cToChar( "BUTTON" ) }
   METHOD Init( hDlg ) BLOCK ;
                { | Self, hDlg | Super:Init( hDlg ),;
                  ::SendMsg( BM_SETCHECK, If( Eval( ::bSetGet ), 1, 0 ) ) }

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( nRow, nCol, cCaption, bSetGet, oWnd, nWidth, nHeight, nHelpTopic,;
            bClick, oFont ) CLASS TCheckBox

   DEFAULT cCaption   := "&CheckBox",;
           oFont      := TFont():New( "System", 8, 9 ),;
           nWidth     := Len( cCaption ) * oFont:nWidth,;
           nHeight    := oFont:nHeight + Int( oFont:nHeight / 2 ),;
           nHelpTopic := 100

   ::nTop       = nRow * ( oFont:nHeight + Int( oFont:nHeight / 2 ) )
   ::nLeft      = ( nCol * oFont:nWidth ) + 3
   ::nBottom    = ::nTop + nHeight
   ::nRight     = ::nLeft + nWidth - 24
   ::cCaption   = cCaption
   ::nStyle     = nOR( WS_CHILD, WS_VISIBLE, BS_AUTOCHECKBOX, WS_TABSTOP )
   ::nId        = ::GetNewId()
   ::nHelpId    = nHelpTopic
   ::bSetGet    = bSetGet
   ::bClick     = bClick
   ::oWnd       = oWnd
   ::oFont      = oFont

   if oWnd:ClassName() != "TDIALOG"
      ::Create( "BUTTON" )
      ::SendMsg( BM_SETCHECK, If( Eval( ::bSetGet ), 1, 0 ) )
   else
      oWnd:DefControl( Self )
   endif

return

//----------------------------------------------------------------------------//

METHOD Click() CLASS TCheckBox

   if ::bSetGet != nil
      Eval( ::bSetGet, ! Eval( ::bSetGet ) )
   endif

   if ::bClick != nil
      Eval( ::bClick, Eval( ::bSetGet ) )
   endif

return

//----------------------------------------------------------------------------//

METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, bClick ) CLASS TCheckBox

   ::nId     = nId
   ::bSetGet = bSetGet
   ::bClick  = bClick
   ::oWnd    = oWnd
   ::nHelpId = nHelpId

   oWnd:DefControl( Self )

return

//----------------------------------------------------------------------------//
